package com.itheima.controller;

import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    //远程注入
  @Reference
  private SetmealService setmealService;
    //移动端查询
    @RequestMapping("getAllSetmeal")
    public Result getAllSetmeal(){
        try{
           List<Setmeal> list=setmealService.findAll();
            return new Result(true, MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS,list);
        }catch(Exception e){
            e.printStackTrace();
            //如果失败 则返回失败
            return new Result(false, MessageConstant.GET_SETMEAL_COUNT_REPORT_FAIL);
        }
    }

    //根据套餐ID查询对应的检查组信息和检查项信息
    @RequestMapping("findById")
    public Result findById(Integer id){
        try{
            Setmeal setmeal=setmealService.findAllById(id);
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        }catch(Exception e){
            e.printStackTrace();
            //如果失败 则返回失败
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

}
